/*
 * LoginForm.java
 * 
 * Version information
 * 
 * Mar 16, 2006
 * 
 * Copyright (c) AmSoft Systems, 2006
 */
package net.amsoft.iservice.ilink.webapp.struts.form;

import javax.servlet.http.HttpServletRequest;

import net.amsoft.iservice.ilink.util.ILinkConstants;
import net.amsoft.iservice.util.IServiceUtil;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

/**
 * @author rahul
 * 
 */
@SuppressWarnings("serial")
public class LoginForm extends ActionForm {

	private String sSynonym;

	public String getSynonym() {
		return sSynonym;
	}

	public void setSynonym(String synonym) {
		sSynonym = synonym;
	}

	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		ActionErrors oErrors = new ActionErrors();
		 if (sSynonym != null || sSynonym.trim().length() != 0) {
	        	sSynonym = sSynonym.trim().toLowerCase();
	            sSynonym = IServiceUtil.getIName(sSynonym);
	        }
	        
	        // raise error if i-name not a valid XRI/HXRI
	        if (sSynonym == null || sSynonym.trim().length() == 0) {
	            oErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
	                    ILinkConstants.ERR_INVALID, "synonym"));
	        }else {
	            sSynonym = sSynonym.trim().toLowerCase();
	        }
	        return oErrors;
	    }
}